@{
ViewData["Title"] = "商品";
var ps = ViewBag.Data.Commoditys;
var pagebar = ViewBag.Data.PageBar;
}
<div class="row">
  @foreach(var p in ps){
  <div class="col-md-3 col-sm-6">
    <div class="card"
         style="width: 18rem;">
      <img src="/upload/@p.Photo"
           style="height: 240px;"
           class="card-img-top"
           alt="商品图片">
      <div class="card-body">
        <div class="height:120px; overflow:hidden;">
          <h5 class="card-title">@p.Cm_name</h5>
          <p class="card-text">@p.introduce</p>
        </div>
        <div class="d-flex justify-content-between">
          <span class="text-danger">￥&nbsp;@p.Price</span>
          <a href="javascript:void(0)"
             class="btn btn-danger btn-cart-plus"
             data-commodityid="@p.CommodityID"
             data-oldprice="@p.Price">
            <i class="bi bi-cart-plus"></i>&nbsp;购物车</a>
        </div>
      </div>
    </div>
  </div>
  }
</div>
<div class="card-footer d-flex justify-content-end"
     style="height: 60px;">
  <nav aria-label="..."
       class="mt-1">
    <ul class="pagination">
      <li class='page-item @(pagebar.CurrentPage==1?"disabled":"")'>
        <a class="page-link"
           asp-controller="Commodity"
           asp-action="GetPage"
           asp-route-page="@pagebar.Previous"
           asp-route-pageSize="@pagebar.PageSize">Previous</a>
      </li>
      @foreach(var btn in pagebar.ButtonGroup){
      <li class='page-item @(pagebar.CurrentPage==btn?"active":"")'>
        <a class="page-link"
           asp-controller="Commodity"
           asp-action="GetPage"
           asp-route-page="@btn"
           asp-route-pageSize="@pagebar.PageSize">@btn</a>
      </li>
      }
      <li class='page-item @(pagebar.CurrentPage==pagebar.PageCount?"disabled":"")'>
        <a class="page-link"
           asp-controller="Commodity"
           asp-action="GetPage"
           asp-route-page="@pagebar.Next"
           asp-route-pageSize="@pagebar.PageSize">Next</a>
      </li>
    </ul>
  </nav>
</div>
</div>
@section Scripts
{
<script>
  $(function () {
    $(".btn-cart-plus").on("click", function () {
      if (!!($("#denglu").attr("id"))) {
        alert("请先登录，再使用购物车！");
        return;
      }

      var btn = $(this);
      $.ajax({
        type: "put",
        url: "/shopcart/info",
        data: {
          commodityid: btn.data("commodityid"),
          oldprice: btn.data("oldprice")
        },

        success: function (response) {
          alert(response.message);
        }
      });
    })
  });
</script>
}
